package com.demo.webapp.kcfinder.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.filefilter.AbstractFileFilter;

/**
 * 文件名称过滤器
 * @author ryuu.kk
 *
 */
public class FileCustomNameFilter extends AbstractFileFilter {

	/**
	 * 默认开启通配符验证
	 */
	private boolean allwoWildcard = true;
	
	private List<String> filenameList;
	
	public FileCustomNameFilter(boolean allwoWildcard, String... filenames) {
		this.allwoWildcard = allwoWildcard;
		this.filenameList = new ArrayList<String>();
	
		for (String filename : filenames) {
			filenameList.add(filename);
		}
	}
	@Override
	public boolean accept(File dir, String name) {
		
		//文件名验证
		for (String s : filenameList) {
			if (allwoWildcard && name.matches(s)) {
				return true;
			}
			if (s.equals(name)) {
				return true;
			}
		}
		return false;
	}

}
